package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.ProblemSearchBean;
import com.renwei.yunlong.utils.DateTimeUtils;
import com.renwei.yunlong.utils.StringUtils;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 服务商 问题查询
 * <p>
 * Created by Administrator on 2017/9/13.
 */

public class ProblemSearchAdapter extends BaseRecyclerViewAdapter<ProblemSearchBean.Rows> {

    public ProblemSearchAdapter(Context context) {
        super(context);
    }

    @Override
    public ServiceProblemInquireViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_work_relate, parent, false);
        return new ServiceProblemInquireViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {
        ServiceProblemInquireViewHolder holder = (ServiceProblemInquireViewHolder) rholder;
        final ProblemSearchBean.Rows rows = getItem(position);

        holder.tvTitleContent.setText(StringUtils.value(rows.getContent()));
        if (TextUtils.isEmpty(rows.getDepartmentName())) {
            holder.tvName.setText("/" + StringUtils.value(rows.getDepartmentName()));
        } else {
            holder.tvName.setText(StringUtils.value(rows.getDepartmentName()) + "/" + StringUtils.value(rows.getRequestUserName()));
        }
        if (!TextUtils.isEmpty(rows.getQuestionDate())) {
            holder.tvTime.setText(DateTimeUtils.stampToDateNow(DateTimeUtils.string2Long(
                    rows.getQuestionDate().replace("T", " "), "yyyy-MM-dd HH:mm:ss")));
        }
        holder.tvLeader.setVisibility(View.GONE);
        holder.button.setText("已解决");
        holder.button.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_76c56d));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v, position);
            }
        });
    }

    static class ServiceProblemInquireViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tv_leader)
        TextView tvLeader;
        @Bind(R.id.tv_title_content)
        TextView tvTitleContent;
        @Bind(R.id.button)
        TextView button;
        @Bind(R.id.tv_name)
        TextView tvName;

        public ServiceProblemInquireViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
